package com.firefly.service.command.cms;

import com.firefly.dao.dao.cms.po.ArticlePo;
import com.firefly.dao.assembler.cms.ArticleAssembler;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.cms.ArticleDto;
import com.firefly.service.repository.cms.ArticleRepository;
import com.firefly.util.utils.FuncUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description: 文章
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/20
 **/
@Service
public class ArticleCommand {
    private final ArticleAssembler articleAssembler;
    private final ArticleRepository articleRepository;
    @Autowired
    public ArticleCommand(ArticleAssembler articleAssembler,ArticleRepository articleRepository){
        this.articleAssembler = articleAssembler;
        this.articleRepository = articleRepository;
    }
    public Boolean create(ArticleDto request){
        ArticlePo entity = articleAssembler.getPo(request);
        // 生成url
        FuncUtils f = new FuncUtils();
        String url = f.getUUIDString();
        entity.setUrl(url);
        return articleRepository.create(entity);
    }
    public Boolean update(ArticleDto request){
        return articleRepository.update(articleAssembler.getPo(request));
    }
    public Boolean remove(CommonDto request){
        return articleRepository.removeByIds(request.detailIds);
    }
}
